<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
	<head>
		<title>工序汇报</title>
		<t:base type="jquery,easyui,tools,DatePicker,utils,yongxin2_js,yongxin_css,mobile_css"></t:base>
	</head>

	<script>
	$(document).ready(function(){
	    
        $("#fworkshop").val('1001');
        
        	    //  存在分卷，就显示分卷信息	    
	    if(${fn:length(productList2)  > 0}){
            document.getElementById('tfoot').hidden = false;
            
            document.getElementById('fbfzl').readOnly = false;
          }
    });
    
 	$(function(){
 			$.ajax({
				type : "POST",
				url : "processReport11Controller.do?getProcess&fbcph=${processReportPage.fbcph}",
				data: {},
				success : function(jsondata) {
						data = $.parseJSON(jsondata);
						var str ="";
						$(data.obj).each(function(i,j){
							//console.log(j);
							
							str +="<span class='progress'>"+j.typename+"("+j.fbcph+")</span>";
							if(i%6==0){
								str +="<br><br>";
							}
							str +="<span >-----></span>";
							//console.log(str);
						});
						//str +=data.msg;
						
						console.log(str);
						$('#div_process').html(str);
						$('#div_nprocess').html(data.msg);
						console.log('${processReportPage.nprocess}');
						$("select[name='nprocess']").val('${processReportPage.nprocess}');
						
						
					}
			});
			
			
			$.ajax({
				type : "POST",
				url : "processReport11Controller.do?getProcess&fbcph=${processReportPage.fbcph}&id=fnprocess",
				data: {},
				success : function(jsondata) {
						data = $.parseJSON(jsondata);
						var str ="";
						$(data.obj).each(function(i,j){
							//console.log(j);
							
							str +="<span class='progress'>"+j.typename+"("+j.fbcph+")</span>";
							if(i%6==0){
								str +="<br><br>";
							}
							str +="<span >-----></span>";
							//console.log(str);
						});
						//str +=data.msg;
						console.log(str);
						
						$('.div_nprocess').each(function(i){
							$(this).html(data.msg);
							$("select[name='fnprocess']").val('over');
						});
						
					}
			});
			
		            var num = ${len<=0 ? 1: len + 1};
		
			var lastCommunAddTr = $(".trRecords:last");

		    $("#add_btn").click(function() {                      //增加行
		      
		       document.getElementById('tfoot').hidden = false;
		       document.getElementById('fbfzl').readOnly = false;
		   	   
               var tr = $("#temp_tr_records").clone();
               tr.attr('id',tr.attr('id')+lpad(num+"",'0',2));
          		
          	   tr.attr('class','trRecords');          		
           		
           	  if("${processReportPage.fbcph}".indexOf("-")>0){
           		
           		tr.find("#ffjh").get(0).value ="${processReportPage.fbcph}"+lpad(num+"",'0',2);
           			
           	  }else{
           	  
           		tr.find("#ffjh").get(0).value ="${processReportPage.fbcph}-"+lpad(num+"",'0',2);
           	  }
           		
               tr.insertAfter(lastCommunAddTr);
               lastCommunAddTr = tr;
               
               num++;
               $('.nprocess:not(:first)').val('over');
            });
            
            
            $("#del_btn").click(function() {                      //删除行
              
            var delIndexs = new Array(0);
              
             // 删除选中的行
            $(".trRecords:gt(0)").each(function(i) {
              		
			   if($(this).find("#ck").get(0).checked == true){
                    delIndexs.splice(delIndexs.length,0,i);
                   	$(this).remove();
               }
           });
                
               
            //  删除后分卷号重新排序
            
            $(".trRecords:not(:first)").each(function(i) {
                	
			    if("${processReportPage.fbcph}".indexOf("-")>0){
				
				    $(this).find("#ffjh").get(0).value ="${processReportPage.fbcph}"+lpad((i+1)+'','0',2);
				
			    }	
			   else{
				
				 $(this).find("#ffjh").get(0).value = "${processReportPage.fbcph}-"+lpad((i+1)+'','0',2);
				
			   }
			   
		 	   num=$(".trRecords:not(:first)").length + 1;
		 			
		       lastCommunAddTr = $(this);
         
            });
              
             // 所有分卷删除之后隐藏分卷信息
             if($(".trRecords:not(:first)").length == 0){
                  num = ${len <=0 ? 1: len + 1};
                  lastCommunAddTr = $(".trRecords");
                  document.getElementById('tfoot').hidden = true; 
                  document.getElementById('fbfzl').readOnly = true;
              }
            
         });
         
         
                
         $("#save_btn").click(function() {             //保存操作
         top.$(".ui_state_highlight").hide();
         if($("#fcczl").val() == ""){
			tip("请填写剩余重量");
			$("#fcczl").focus();
			return false;
		 } 
		 	 //报废重量不能为空
		if($("#fbfzl").val() == ""){
			tip("请填写报废重量");
			$("#fbfzl").focus();
			return false;
		}   
		
		 var ffjhs = $("input[name='ffjhs']:not(:last)");
	   
	   //没有分卷：投入重量 = 剩余重量 + 报废重量
	   if(ffjhs.length == 0){
	      var ftrzl = parseFloat($('#ftrzl').val(),10);
	      var fcczl = parseFloat($('#fcczl').val(),10);
	      if(fcczl > ftrzl){
	      tip("剩余重量不能大于投入重量");
          $('#fcczl').focus();
          return false;
	      }
	   }
	   else if($('#fcczl').val()!= ""){
      
       var a = $('#ftrzl').val();
       var b = $('#fcczl').val();
       var c = $('#fbfzl').val();
       
       a = parseFloat(a,10);
       b= parseFloat(b,10);
       c= parseFloat(c,10);
         
       if(b > a){
         tip("剩余重量不能大于投入重量");
         $('#fcczl').focus();
         return false;
       }
      
	  }
		
		
		
         ajaxdoForm('processReport11Controller.do?save&fstate=1','formobj');
         	$("#save_btn").hide();
            $("#add_btn").hide();
            $("#del_btn").hide();
      });
            
            
            selChange();
 	})
    
      function selChange(){

      var sel = $("#fworkshop").val();
      $.ajax({
		type : "POST",
		url : "processReportController.do?getMatchinegroupList&process=${processReportPage.cprocess}",
		data: {pid:$('#fworkshop').val()},
		success : function(jsondata) {
				data = $.parseJSON(jsondata);
				console.log(data);
				$('#fmatchinegroup').html(data.msg);
			  	$('#fmatchinegroup').val("${processReportPage.fmatchinegroup}");
			}
	});
	
}
	
	//  计算分切投入重量
	function getTrzls(){
	   
	   var ffjhs = $("input[name='ffjhs']:not(:last)");
	   
	   //没有分卷：投入重量 = 剩余重量 + 报废重量
	   if(ffjhs.length == 0){
	      var ftrzl = parseFloat($('#ftrzl').val(),10);
	      var fcczl = parseFloat($('#fcczl').val(),10);
	      if(fcczl > ftrzl){
	      tip("剩余重量不能大于投入重量");
          $('#fcczl').focus();
          return false;
	      }
	      $('#fbfzl').val((ftrzl-fcczl).toFixed(2));
	   }
	   else if($('#fcczl').val()!= ""){
      
       var a = $('#ftrzl').val();
       var b = $('#fcczl').val();
       var c = $('#fbfzl').val();
       
       a = parseFloat(a,10);
       b= parseFloat(b,10);
       c= parseFloat(c,10);
       
       if(b > a){
         tip("剩余重量不能大于投入重量");
         $('#fcczl').focus();
         return false;
       }
  
       $('#ftrzls').val((a - b - c).toFixed(2));
     
	  }
	 else{
	   $('#ftrzls').val("");
	 }
	  
	 if($('#fcczl').val()== "0"){
	   $("select[name='nprocess']").val('over');
	 }else{
	   $("select[name='nprocess']").val('p11');
	 }
	 
  }
 </script>
  <style type="text/css">

  table th{
  word-break: keep-all;white-space:nowrap;
  }
  
  table td{
  word-break: keep-all;white-space:nowrap;
  }  
  </style>
	<body  scroll="no">
		<div id="wrapper">
					<t:formvalid formid="formobj" dialog="true" usePlugin="password" layout="table" tiptype="1"
						action="processReport11Controller.do?save&fstate=2" beforeSubmit="checkChromate">
						<input id="id" name="id" type="hidden" value="${processReportPage.id }">
						<input type="hidden" id="cprocess" name="cprocess" class="mytxt" ignore="ignore" value="${processReportPage.cprocess}">
						<input type="hidden" id="f_fbcph" name="f_fbcph" class="mytxt" ignore="ignore">
						<table  cellpadding="0" cellspacing="1" class="formtable">
							<tr>
								<td align="center" colspan=11>
									<label class="Validform_label">
										镀铬工序汇报单
									</label>
								</td>
							</tr>
							<tr>
								<td align="center" colspan=11 style="background-color: white; padding: 20px">
									<div id="div_process"></div>
								</td>
							</tr>
							<tr style="display: none">
								<td align="center">
									<label class="Validform_label">
										制单时间
									</label>
								</td>
								<td class="value" colspan=10>
									<input class="mytxt" style="width: 140px" id="updateDate" name="updateDate" class="mytxt" ignore="ignore"
										value="<fmt:formatDate value='${processReportPage.updateDate}' type="date" pattern="yyyy-MM-dd HH:mm:ss"/>" ReadOnly>
									<!--<input class="Wdate" onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" style="width: 150px" id="createDate"
							name="createDate" class="mytxt"  ignore="ignore">   -->
								</td>
							</tr>
							<tr>
								<td align="center">
									<label class="Validform_label">
										生产车间
									</label>
								</td>
								<td class="value" colspan=10>
									<!--<t:dictSelect field="fworkshop" typeGroupCode="workshop" hasLabel="false"  defaultVal="${processReportPage.fworkshop}" extendJson="{id:sel2}"></t:dictSelect>
								-->
								    <select  id="fworkshop"  name="fworkshop" onchange="selChange()">
								     <c:forEach items="${workshopList}" var="workshop">
								        <option value="${workshop.id}"   <c:if test="${workshop.id==processReportPage.fworkshop}"> selected="selected"</c:if>>${workshop.name}</option>
								     </c:forEach>
								     </select>
								</td>
							</tr>
							<tr>
								<td align="center">
									<label class="Validform_label">
										班组
									</label>
								</td>
								<td class="value" colspan=10>
									 <t:dictSelect field="fworkgroup" typeGroupCode="team" hasLabel="false"  defaultVal="${processReportPage.fworkgroup}" extendJson="{id:sel2}"></t:dictSelect>

								</td>
							</tr>
							<tr>
								<td align="center">
									<label class="Validform_label">
										机组
									</label>
								</td>
								<td class="value" colspan=10>
									<!--<input id="fmatchinegroup" name="fmatchinegroup" style="width: 140px" class="mytxt" ignore="ignore"
										value="${processReportPage.fmatchinegroup}">
								-->
								 <select id='fmatchinegroup' name='fmatchinegroup'><option value=''>请选择</option></select>
								</td>
							</tr>
							<tr style="display: none">
								<td align="center">
									<label class="Validform_label">
										制单人
									</label>
								</td>
								<td class="value" colspan=10>
									<input id="createBy" name="createBy" style="width: 140px" class="mytxt" ignore="ignore" readOnly
										value="${processReportPage.createBy}">
								</td>
							</tr>
							<tr>
								<td align="center">
									<label class="Validform_label">
										本厂批号
									</label>
								</td>
								<td align="center">
									<label class="Validform_label">
										投入厚度
									</label>
								</td>
								<td align="center">
									<label class="Validform_label">
										投入宽度
									</label>
								</td>
								<td align="center">
									<label class="Validform_label">
										投入重量
									</label>
								</td>
								<td align="center">
									<label class="Validform_label">
										产出厚度
									</label>
								</td>
								<td align="center">
									<label class="Validform_label">
										产出宽度
									</label>
								</td>
								<td align="center">
									<label class="Validform_label">
										剩余重量
									</label>
								</td>
								<td align="center">
									<label class="Validform_label">
										报废重量
									</label>
								</td>
								<td align="center">
									<label class="Validform_label">
										质量情况
									</label>
								</td>
								<td align="center">
									<label class="Validform_label">
										下一道工序
									</label>
								</td>
							</tr>
							<tr id="record_tr" class="trRecord">
								<td class="value" style="text-align: right">
									<input id="fbcph" name="fbcph" class="mytxt" ignore="ignore" value="${processReportPage.fbcph}" style="width: 120px"
										ReadOnly>
										<input  name="fwlname"  type="hidden" value="${processReportPage.fwlname}" >
								</td>
								<td align="right" class="value">
									<input id="ftrhd" name="ftrhd" class="mytxt" ignore="ignore" value="${processReportPage.ftrhd}">
								</td>
								<td align="center" class="value">
									<input id="ftrkd" name="ftrkd" class="mytxt" ignore="ignore" value="${processReportPage.ftrkd}">
								</td>
								<td align="center" class="value">
									<input id="ftrzl" name="ftrzl" class="mytxt" ignore="ignore" value="${processReportPage.ftrzl}">
								</td>
								<td align="center" class="value">

									<input id="fcchd" name="fcchd" class="mytxt" ignore="ignore" dataType="d" value="${processReportPage.ftrhd}">
								</td>
								<td align="center" class="value">
									<input id="fcckd" name="fcckd" class="mytxt" ignore="ignore" dataType="d" value="${processReportPage.ftrkd}" >
								</td>
								<td align="center" class="value">
									<input id="fcczl" name="fcczl" class="mytxt" ignore="ignore" dataType="d"  onKeyUp="getTrzls()" value="${processReportPage.fcczl}" >
								</td>
								<td align="center" class="value">
									<input id="fbfzl" name="fbfzl" class="mytxt" ignore="ignore" dataType="d" readonly="readonly"  onKeyUp="getTrzls()"  value="${processReportPage.fbfzl}" >
								</td>
								<td align="center" class="value">
									<input id="fnote" name="fnote" class="mytxt" ignore="ignore" value="${processReportPage.fnote}">
								</td>
								<td align="center" class="value">
									<div id="div_nprocess"></div>
								</td>
							</tr>
				           <tfoot hidden="true" id="tfoot">		
							<tr>
								<td align="center">
									<label class="Validform_label">
										本厂批号
									</label>
								</td>
								<td align="center">
									<label class="Validform_label">
										投入厚度
									</label>
								</td>
								<td align="center">
									<label class="Validform_label">
										投入宽度
									</label>
								</td>
								<td align="center">
									<label class="Validform_label">
										投入重量
									</label>
								</td>
								<td align="center">
									<label class="Validform_label">
										分卷号
									</label>
								</td>
								<td align="center">
									<label class="Validform_label">
										长度
									</label>
								</td>
								<td align="center">
									<label class="Validform_label">
										分切重量
									</label>
								</td>
								<td align="center">
									<label class="Validform_label">
										下一工序
									</label>
								</td>
								<td align="center" colspan="2">
									<label class="Validform_label">
										备注
									</label>
								</td>

							</tr>

								<tr id="records_tr" class="trRecords">
									<td align="center" class="value" style="text-align: right" rowspan=100>
										<input id="fbcph" name="bcph" class="mytxt" ignore="ignore" style="width: 120px" value="${processReportPage.fbcph}"
											ReadOnly>
									</td>
									<td align="center" class="value" style="text-align: right" rowspan=100>

										<input id="ftrhds" name="ftrhds" class="mytxt" ignore="ignore" dataType="d" value="${processReportPage.ftrhd}">
									</td>
									<td align="center" class="value" rowspan=100>
										<input id="ftrkds" name="ftrkds" class="mytxt" ignore="ignore" dataType="d" value="${processReportPage.ftrkd}">
									</td>
									<td align="center" class="value" rowspan=100>
										<input id="ftrzls" name="ftrzls" class="mytxt" value="${ftrzls}" ignore="ignore"  ReadOnly>
									</td>
									</tr>			
											
											<c:if test="${fn:length(productList2)  > 0 }">
								<c:forEach items="${productList2}" var="poVal" varStatus="stuts">		
												<tr class="trRecords">
												<td align="left" class="value">
										        <input type="checkbox" id="ck"  >
												<input id="ffjh" name="ffjhs" style="width: 120px" class="mytxt" ignore="ignore" value="${poVal.ffjh}" ReadOnly>
										</td>
										<td align="center" class="value">
											<input id="fcds" name="fcds" class="mytxt" ignore="ignore" dataType="d" value="${poVal.fcd}">
										</td>
										<td align="center" class="value">
											<input id="ffqzls" name="ffqzls" class="mytxt" ignore="ignore" dataType="d" value="${poVal.ffqzl}">
										</td>
										<td align="center" class="value" >
											<div id="t_div_nprocess" class="div_nprocess"></div><span style="display:none">${poVal.nprocess}</span>
										</td>
										<td align="center" class="value" colspan="2">
											<input id="fnote" name="fnotes" style="width: 200px;" class="mytxt" ignore="ignore" value="${poVal.fnote}">
										</td>
									</tr>
								</c:forEach>
							</c:if>
								
								
								
								</tfoot>
						</table>
					</t:formvalid>
					<div id="dlg-buttons" >
						<table cellpadding="0" cellspacing="0" style="width: 100%">
							<tr>

								<td style="text-align: left; padding-top: 10px">
									<a href="#" class="easyui-linkbutton btn" iconCls="icon-save" id="save_btn">保存</a>
									<a href="#" class="easyui-linkbutton btn" iconCls="icon-add" id="add_btn">增加分切</a>
									<a href="#" class="easyui-linkbutton btn" iconCls="icon-remove" id="del_btn">删除分切</a>
								</td>
							</tr>
						</table>
					</div>
                     <div style="margin-left: 20px;margin-top: 30px;">
                    
                    <span style="font-family: Microsoft YaHei;font-size: 14px;color: red"> 注：当分卷直接入库时，分切重量不需要填写</span>
                    </div>


					<table style="width: 600px; display: none" cellpadding="0" cellspacing="1">

						<tr id="temp_tr_records">
							<td align="left" class="value">
								<input type="checkbox" id="ck">
								<input id="ffjh" name="ffjhs" style="width: 120px;" class="mytxt" ignore="ignore"  ReadOnly>
							</td>
							<td align="center" class="value">
								<input id="fcds" name="fcds" class="mytxt" ignore="ignore" dataType="d">
							</td>
							<td align="center" class="value">
								<input id="ffqzls" name="ffqzls" class="mytxt" ignore="ignore">
							</td>
							<td align="center" class="value" >
								<div id="t_div_nprocess" class="div_nprocess"></div>
							</td>
							<td align="center" class="value" colspan="2">
								<input id="fnotes" name="fnotes" style="width: 200px;" class="mytxt" ignore="ignore">
							</td>
						</tr>
					</table>
				</div>
	</body>